package com.sinochem.yunlian.ship.base.biz;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sinochem.yunlian.ship.api.vo.bs.BsNodeVO;
import com.sinochem.yunlian.ship.base.constants.BsNodeConstant;
import com.sinochem.yunlian.ship.base.entity.BsNode;
import com.sinochem.yunlian.ship.base.entity.BsNodeItem;
import com.sinochem.yunlian.ship.base.mapper.BsNodeItemMapper;
import com.sinochem.yunlian.ship.base.mapper.BsNodeMapper;
import com.sinochem.yunlian.ship.common.biz.BaseBiz;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 任务节点表
 *
 * @author wh
 * @email ${email}
 * @date 2017-11-24 15:50:39
 */
@Service
public class BsNodeBiz extends BaseBiz<BsNodeMapper,BsNode> {
    @Autowired
    private BsNodeItemMapper nodeItemMapper;

    public List<BsNode> findAllNodes(){
        return super.mapper.selectAllNodes();
    };

    public List<BsNode>  findAllNotRequiredNodes(Integer nodeType){
        Map inMap = new HashMap();
        inMap.put("deleteStatus", BsNodeConstant.NODE_STATUS_NORMAL);
        inMap.put("status", BsNodeConstant.STATUS_ENABLE);
        inMap.put("required", BsNodeConstant.NODE_REQUIRED_NOT);
        inMap.put("nodeType",nodeType);
        return super.mapper.findNodeByCondition(inMap);
    };

    public List<BsNode>  findAllRequiredNodes(Integer nodeType){
        Map inMap = new HashMap();
        inMap.put("deleteStatus", BsNodeConstant.NODE_STATUS_NORMAL);
        inMap.put("status", BsNodeConstant.STATUS_ENABLE);
        inMap.put("required", BsNodeConstant.NODE_REQUIRED);
        inMap.put("nodeType",nodeType);
        return super.mapper.findNodeByCondition(inMap);
    };

    public List<BsNode>  findAllNodesByType(Integer nodeType){
        Map inMap = new HashMap();
        inMap.put("deleteStatus", BsNodeConstant.NODE_STATUS_NORMAL);
        inMap.put("status", BsNodeConstant.STATUS_ENABLE);
        inMap.put("nodeType",nodeType);
        return this.mapper.findNodeByCondition(inMap);
    };

    public List<BsNodeItem> findAllNodeItems(){
        return nodeItemMapper.findAllNodeItems();
    }

    public Page<BsNode> findNodeByCondition(Map params){
        Page<BsNode> result = PageHelper.startPage(Integer.parseInt(params.get("pageNum")+""),Integer.parseInt(params.get("pageSize")+""));
        this.mapper.findNodeByCondition(params);
        return result;
    }
}